from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from app.database import get_db
from app import models, schemas

router = APIRouter(prefix="/categories", tags=["分类"])


@router.get("", response_model=schemas.Response)
async def list_categories(db: Session = Depends(get_db)):
    """获取分类列表"""
    categories = db.query(models.Category).order_by(models.Category.sort.asc()).all()
    return schemas.Response(
        data=[schemas.CategoryResponse.from_orm(c) for c in categories]
    )

